<script setup>

import { onMounted,ref,onBeforeUnmount } from 'vue';

const KEY = 'IFRAME_DOC'
const href = location.origin
const doc = localStorage.getItem(KEY) || '';
const iframeRef = ref();
// onMounted(() => {
//     console.log(iframeRef.value,iframeRef.value.contentDocument)
//     iframeRef.value.onload = () => {
//         console.log('+++++++++++++++')
//         console.log(iframeRef.value,[iframeRef.value?.contentDocument.documentElement.outerHTML])
//     }
// })

onBeforeUnmount(() => {
    localStorage.setItem(KEY,iframeRef.value?.contentDocument.documentElement.outerHTML)
})
</script>

<template>
    <iframe v-if="doc" ref="iframeRef"  :srcdoc="doc" class="w-full h-full relative overflow-auto"></iframe>
    <iframe v-else ref="iframeRef" :src="href"  class="w-full h-full relative overflow-auto"></iframe>
</template>